package com.laolang.ssh.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.laolang.ssh.config.DataSourceConfig;
import com.laolang.ssh.domain.BookType;
import com.laolang.ssh.service.BookTypeService;

@Controller
@RequestMapping("/booktypes")
public class BookTypeController {
	
	Logger log = LoggerFactory.getLogger(BookTypeController.class);
	
	@Autowired
	private DataSourceConfig dataSourceConfig;
	
	@Autowired
	private BookTypeService bookTypeService;
	
	
	@RequestMapping(value="booktypes",method=RequestMethod.GET,produces="text/html")
	public String booktypes( Model model ){
		log.info("加载图书类别列表");
		System.out.println(dataSourceConfig.getDriverClass());
		System.out.println(dataSourceConfig.getPassWord());
		System.out.println(dataSourceConfig.getUrl());
		System.out.println(dataSourceConfig.getUserName());
		
//		BookType bookType = new BookType("教育", "教育", "-", true);
		BookType bookType = new BookType();
		bookType = bookTypeService.findById(1);
		bookType.setTypeName("计算机");
		bookTypeService.merge(bookType);
		System.out.println(bookType.toString());
		model.addAttribute("bookType", bookType);
		return "booktype/booktypes";
	}

}
